package com.ra.controller;


import com.ra.pojo.RespBean;
import com.ra.pojo.dto.*;
import com.ra.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 今晚几点睡_Ada
 * @since 2023-03-09
 */
@RestController
@Api(tags = "菜单模块模块")
public class MenuController {
    @Autowired
    private IMenuService menuService;

    @ApiOperation(value = "查看当前用户菜单")
    @GetMapping("/admin/user/menus")
    public RespBean<?> listUserMenus() {
        return  menuService.getMenusByUserId();
    }

    @ApiOperation(value = "查看菜单列表")
    @GetMapping("/admin/menus")
    public RespBean<List<MenuDTO>> listMenus(ConditionDTO conditionDTO) {
        return RespBean.success(menuService.listMenus(conditionDTO));
    }
    @ApiOperation(value = "新增或修改菜单")
    @PostMapping("/admin/menus")
    public RespBean<?> saveOrUpdateMenu(@Valid @RequestBody MenuDTO menuDTO) {
        menuService.saveOrUpdateMenu(menuDTO);
        return RespBean.success();
    }
    @ApiOperation(value = "修改目录是否隐藏")
    @PutMapping("/admin/menus/isHidden")
    public RespBean<?> updateMenuIsHidden(@RequestBody IsHidden isHidden) {
        menuService.updateMenuIsHidden(isHidden);
        return RespBean.success();
    }
    @ApiOperation(value = "删除菜单")
    @DeleteMapping("/admin/menus/{menuId}")
    public RespBean<?> deleteMenu(@PathVariable("menuId") Integer menuId) {
        menuService.deleteMenu(menuId);
        return RespBean.success();
    }
    @ApiOperation(value = "查看角色菜单选项")
    @GetMapping("/admin/role/menus")
    public RespBean<List<LabelOptionDTO>> listMenuOptions() {
        return RespBean.success(menuService.listMenuOptions());
    }
}

